package com.itheima.controller;
import com.itheima.domain.SmsHomeRecommendProduct;
import com.itheima.manager.SmsHomeRecommendProductManager;
import com.itheima.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/recommendProduct")
public class SmsHomeRecommendProductController {

    @Autowired
    SmsHomeRecommendProductManager smsHomeRecommendProductManager;

    @PostMapping("/create")
    public R addRecommendProduct(@RequestBody List<SmsHomeRecommendProduct> recommendProducts){
        return smsHomeRecommendProductManager.addRecommendProduct(recommendProducts);

    }

    @PostMapping("/delete")
    public R deleteRecommendProduct(@RequestParam("ids") List<Long> ids) {
        return smsHomeRecommendProductManager.deleteBrand(ids);

    }


    @GetMapping("/list")
    public R findByPage(Integer pageNum, Integer pageSize,String productName,Integer recommendStatus){
        return smsHomeRecommendProductManager.findByPage(pageNum,pageSize,productName,recommendStatus);
    }
    @PostMapping("/update/recommendStatus")
    public R updateRecommendProduct(@RequestParam("ids") List<Long> ids,@RequestParam("recommendStatus") Integer recommendStatus){
        return smsHomeRecommendProductManager.updateRecommendProduct(ids,recommendStatus);

    }

    @PostMapping("/update/sort/{id}")
    public R updatesortRecommendProduct(@PathVariable("id") Long id,@RequestParam(required = false) Integer sort){
        return smsHomeRecommendProductManager.updateSortRecommendProduct(id,sort);

    }
}
